package com.wpw.web.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description:
 * @ClassName: ThrowableTest
 * @CreateDate: 2020-05-17 14:49
 * @author: wupengwei
 */
public class ThrowableTest {



    public static void main(String[] args) throws Exception {
        right2();
    }

    public static void wrong() {
        try {
            System.out.println("try");
            //异常丢失
            throw new RuntimeException("try");
        } finally {
            System.out.println("finally");
            throw new RuntimeException("finally");
        }
    }


    public static void right2() throws Exception {
        Exception e = null;
        try {
            System.out.println("try");
            throw new RuntimeException("try");
        } catch (Exception ex) {
            e = ex;
        } finally {
            System.out.println("finally");
            try {
                throw new RuntimeException("finally");
            } catch (Exception ex) {
                if (e!= null) {
                    e.addSuppressed(ex);
                } else {
                    e = ex;
                }
            }
        }
        throw e;
    }
}